home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / pas_all.zip / TI545.ASC < prev    next >
Text File  |  1992-02-28  |  8KB  |  331 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  TURBO PASCAL                           NUMBER  :  545
  9.   VERSION  :  4.0, 5.0, AND 5.5
  10.        OS  :  PC-DOS 3.0 or later, MS-DOS 3.0 or later
  11.      DATE  :  February 28, 1992                        PAGE  :  1/4
  12.  
  13.     TITLE  :  FILES OPEN EXTEND
  14.  
  15.  
  16.  
  17.  
  18.   The following is public domain information that has been uploaded
  19.   to  our Forum on CompuServe.  As a courtesy to our users that  do
  20.   not  have  immediate  access  to  CompuServe,  Technical  Support
  21.   distributes these routines free of charge.
  22.  
  23.   However,  because these routines are public domain programs,  not
  24.   developed by Borland International,  we are unable to provide any
  25.   technical support or assistance using these routines. If you need
  26.   assistance   using   these   routines,    or   are   experiencing
  27.   difficulties,  we  recommend  that you log  onto  CompuServe  and
  28.   request  assistance  from the Forum members that developed  these
  29.   routines.
  30.  
  31.   The following unit extends the maximum number of  files  that can
  32.   be open simultaneously from 20 to 255.  Files in DOS 2.0 or later
  33.   are  controlled  by  file  handles.   The number of file  handles
  34.   available to application  programs  is  controlled  by  the FILES
  35.   environment  variable  stored  in a CONFIG.SYS file.  If no FILES
  36.   variable  is  established  in a CONFIG.SYS file, then only 8 file
  37.   handles are available.  However,  DOS requires 5 file handles for
  38.   its own use (controlling  devices  such  as  CON, AUX, PRN, etc).
  39.   This le
  40.  
  41.  
  42.   aves only 3 handles for use by application programs.
  43.  
  44.   By specifying a value for the FILES environment variable, you can
  45.   increase the number  of  possible  file  handles from 8 up to 20.
  46.   Since DOS still requires 5, 15 are left for application programs.
  47.   But you cannot normally increase the number of handles beyond 20.
  48.  
  49.   With DOS version 3.0, a new DOS function was  added  to  increase
  50.   the number of file handles available.  However, the function must
  51.   be called from application programs that have previously reserved
  52.   space for the new file handles.
  53.  
  54.   The unit EXTEND, described below, resizes the amount of allocated
  55.   memory for a  Turbo  Pascal  program  to allow space for new file
  56.   handles.  In doing so, it also resizes the heap by  adjusting the
  57.   value of FreePtr, the pointer used in FreeList management.  Since
  58.   the  FreeList  is  being manipulated, the heap must be empty when
  59.   the EXTEND unit  is  initialized.    This  can  be  guaranteed by
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  TURBO PASCAL                           NUMBER  :  545
  75.   VERSION  :  4.0, 5.0, AND 5.5
  76.        OS  :  PC-DOS 3.0 or later, MS-DOS 3.0 or later
  77.      DATE  :  February 28, 1992                        PAGE  :  2/4
  78.  
  79.     TITLE  :  FILES OPEN EXTEND
  80.  
  81.  
  82.  
  83.  
  84.   including EXTEND as one of the first units in your program's USES
  85.   statement.  If any heap has been allocated when EXTEND initialize
  86.  
  87.  
  88.   s, the program will halt with an error message.
  89.  
  90.   Notice  that  the  interface section of the EXTEND unit is empty.
  91.   The initialization section of the unit takes care  of  the unit's
  92.   entire function.  Other than including EXTEND in a program's USES
  93.   statement, no other operation need be preformed.
  94.  
  95.   Before using EXTEND, you  must  specify  a  FILES variable in the
  96.   CONFIG.SYS file such as the following:
  97.  
  98.           FILES = 255
  99.  
  100.   Refer to your DOS User's Guide for more information regarding the
  101.   CONFIG.SYS file and the FILES variable.
  102.  
  103.   The unit EXTEND is set up for 255 file handles.    You can reduce
  104.   this number by changing the HANDLES constant in the unit's source
  105.   code and  reducing the number specified for the FILES environment
  106.   variable.
  107.  
  108.   unit Extend;
  109.   {This extends the number of file handles from 20 to 255}
  110.   {DOS requires 5 for itself. Applications can use up to 250}
  111.  
  112.   interface
  113.  
  114.   implementation
  115.   uses dos;
  116.   const
  117.           Handles =255;
  118.   {You can reduce the value passed to Handles if fewer files}
  119.   {are required.}
  120.  
  121.   var
  122.           reg:registers;
  123.   begin
  124.                   {Check the Dos Version}
  125.                   {This technique only works for DOS 3.0 or later}
  126.   reg.ah:=$30;
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  TURBO PASCAL                           NUMBER  :  545
  141.   VERSION  :  4.0, 5.0, AND 5.5
  142.        OS  :  PC-DOS 3.0 or later, MS-DOS 3.0 or later
  143.      DATE  :  February 28, 1992                        PAGE  :  3/4
  144.  
  145.     TITLE  :  FILES OPEN EXTEND
  146.  
  147.  
  148.  
  149.  
  150.   MsDos(reg);
  151.   if reg.al<3 then
  152.           begin
  153.           writeln('Extend Unit Require DOS 3.0 or greater');
  154.           halt(1);
  155.           end;
  156.  
  157.                   {Reset the FreePtr}
  158.                   {This  reduces  the  heap  space  used  by  Turbo
  159.   Pascal}
  160.   if Ofs(FreePtr^)<>0 then
  161.   {Checks to see if the Heap is empty}
  162.           begin
  163.           write('Heap   must   be   empty   before    Extend   unit
  164.   initializes');
  165.           writeln;
  166.           halt(1);
  167.           end;
  168.   FreePtr:=ptr(Seg(FreePtr^)-(Handles div 8 +1), Ofs(FreePtr^));
  169.  
  170.                   {Determine  how  much  memory  is   allocated  to
  171.   program}
  172.   {Reg.Bx will return how many paragraphs used by program}
  173.   reg.ah:=$4A;
  174.   reg.es:=PrefixSeg;
  175.   reg.bx:=$FFFF;
  176.   msdos(reg);
  177.  
  178.                   {Set  the  program  size  to  the  allow  for new
  179.   handles}
  180.   reg.ah:=$4A;
  181.   reg.es:=PrefixSeg;
  182.   reg.bx:=reg.bx-(Handles div 8 +1);
  183.   msdos(reg);
  184.  
  185.                   {Error when a Block Size is not appropriate}
  186.   if (reg.flags and 1)=1 then
  187.           begin
  188.           Writeln('Runtime Error ',reg.ax);
  189.           Writeln('In the Extend Unit');
  190.           halt(1);
  191.           end;
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  TURBO PASCAL                           NUMBER  :  545
  207.   VERSION  :  4.0, 5.0, AND 5.5
  208.        OS  :  PC-DOS 3.0 or later, MS-DOS 3.0 or later
  209.      DATE  :  February 28, 1992                        PAGE  :  4/4
  210.  
  211.     TITLE  :  FILES OPEN EXTEND
  212.  
  213.  
  214.  
  215.  
  216.                   {Allocate Space for Additional Handles}
  217.   reg.ah:=$67;
  218.   reg.bx:=Handles;
  219.   MsDos(reg);
  220.   end.
  221.  
  222.   Write the following program  to  a  separate  file.  This program
  223.   tests the  extend  unit.    This  test  should be done on systems
  224.   equipped with a hard disk.
  225.  
  226.   program TestEx;
  227.   uses extend;
  228.   type
  229.           filearray=array[1..250] of text;
  230.   var
  231.           f:^filearray;
  232.           i:integer;
  233.           s:string;
  234.  
  235.   begin
  236.                   {Allocate Space for File Variable Table}
  237.   new(f);
  238.                   {Open 250 files simultaneously}
  239.   for i:=1 to 250 do
  240.           begin
  241.           str(i,s);
  242.           Assign(f^[i],'Dum'+s+'.txt');
  243.           rewrite(f^[i]);
  244.           writeln('Open #',s);
  245.           end;
  246.  
  247.                   {Write some text to the files}
  248.   for i:=1 to 250 do
  249.           write(f^[i],'This is a test file');
  250.  
  251.                   {Close the files}
  252.   for i:=1 to 250 do
  253.           begin
  254.           close(f^[i]);
  255.           writeln('Closing #',i);
  256.           end;
  257.  
  258.                   {Erase the files}
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  TURBO PASCAL                           NUMBER  :  545
  273.   VERSION  :  4.0, 5.0, AND 5.5
  274.        OS  :  PC-DOS 3.0 or later, MS-DOS 3.0 or later
  275.      DATE  :  February 28, 1992                        PAGE  :  5/4
  276.  
  277.     TITLE  :  FILES OPEN EXTEND
  278.  
  279.  
  280.  
  281.  
  282.   for i:=1 to 250 do
  283.           begin
  284.           erase(f^[i]);
  285.           writeln('Erasing #',i);
  286.           end;
  287.  
  288.   end.
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.